﻿@using Flagrum.Web.Features.AssetExplorer.Data
@using System.Text
@using Flagrum.Core.Ebex.Xmb2
<div class="p-6 h-full" style="max-height: 100%; max-width: 100%;">
    <div class="box p-4 h-full overflow-auto">
        <Virtualize Items="Lines">
            <span @key="context.Index" class="block" style="white-space: nowrap">@context.Line</span>
        </Virtualize>
    </div>
</div>

@code
{
    private IAssetExplorerNode _previousItem;

    private List<(int Index, string Line)> Lines { get; set; }

    [Parameter]
    public IAssetExplorerNode Item { get; set; }

    protected override void OnParametersSet()
    {
        if (_previousItem == Item)
        {
            return;
        }

        var xmb2 = Item.Data;
        var stringBuilder = new StringBuilder();
        Xmb2Document.Dump(xmb2, stringBuilder);
        var counter = 0;

        Lines = stringBuilder.ToString()
            .Replace(" ", "\u00A0")
            .Split('\n')
            .Select(l => (counter++, l))
            .ToList();

        StateHasChanged();
    }
}